package com.iring.service.common.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iring.dao.common.PayAmountDao;
import com.iring.domain.common.AmountTask;
import com.iring.service.common.PayAmountService;

/**
 * @author wanggan
 */
@Service
public class PayAmountServiceImpl implements PayAmountService {

    @Autowired
    PayAmountDao payAmountDao;

    @Override
    public List<AmountTask> findByUsername(String username) {
        // optstatus 0未操作 1 已经操作
        return payAmountDao.findByUsernameAndOptstatus(username, 0);
    }

    @Override
    public List<AmountTask> finAllExceptionUndealTask() {
        return payAmountDao.finAllExceptionUndealTask();
    }

    @Override
    public Boolean updateExceptionOrderStutus(String payid) {
        Integer res = payAmountDao.updateExceptionOrderStutus(payid);
        if (res == 0) {
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    public Boolean createTask(AmountTask amountTask) {
        AmountTask task = new AmountTask();
        task.setCreatetime(null);
        task.setOptamounts(amountTask.getOptamounts());
        task.setOptstatus(0);
        task.setOpttype(1);
        task.setOrderid(amountTask.getOrderid());
        task.setUsername(amountTask.getUsername());
        task = payAmountDao.save(task);
        if (task.getId() != null) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
}
